home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_usrdoc / SVGALIB-.{2E / SVPMI / SVPMI.C < prev    next >
C/C++ Source or Header  |  1999-09-17  |  4KB  |  186 lines

  1. /* This library is free software; you can redistribute it and/or   */
  2. /* modify it without any restrictions. This library is distributed */
  3. /* in the hope that it will be useful, but without any warranty.   */
  4.  
  5. /* Copyright (C) 1994 Harm Hanemaayer */
  6.  
  7. /*
  8.    Basic initial untested SVPMI skeleton driver.
  9.    Includes computer-generated mode setting/bank switching
  10.    routines and mode information table.
  11.  
  12.    Untested, may not be finished.
  13.  
  14.    A better way to do this would be to have a seperate svpmi server
  15.    program      set modes. This way there would be no need to recompile
  16.    the shared library. For performance it would be nice to move the
  17.    bank-switching over to svgalib. I imagine one way to do this would
  18.    be to encode the SVPMI procedure code (simple as it is, just a few
  19.    outs and a few basic bit operations) and have the svgalib driver
  20.    interpret that. This could also be used for mode setting.
  21.  */
  22.  
  23.  
  24. #include <stdio.h>
  25. #include "../vga.h"
  26. #include "../libvga.h"
  27. #include "../driver.h"
  28.  
  29. #include "svpmi.h"
  30. #include "modes.svpmi"
  31. #include "modetable.svpmi"
  32.  
  33.  
  34.  
  35. static svpmi_currentmode = NULL;
  36.  
  37. static svpmi_modeentry *
  38. svpmi_lookupmode (int w, int h, int colors)
  39. {
  40.   int i;
  41.   for (i = 0; i < sizeof (svpmi_modes); i++)
  42.     if (w == svpmi_modes[i].width && h == svpmi_modes[i].height &&
  43.     colors = (1 << svpmi_mode[i].bitsperpixel))
  44.       return &svpmi_modes[i];
  45.   return NULL;
  46. }
  47.  
  48.  
  49. static int
  50. svpmi_getmodeinfo (int mode, vga_modeinfo * modeinfo)
  51. {
  52.   modeinfo->maxlogicalwidth = modeinfo->width;
  53.   modeinfo->startaddressrange = 0;
  54.   modeinfo->haveblit = 0;
  55.   modeinfo->flags &= ~HAVE_RWPAGE;
  56.   return 0;
  57. }
  58.  
  59.  
  60. /* Return non-zero if mode is available */
  61.  
  62. static int
  63. svpmi_modeavailable (int mode)
  64. {
  65.   struct info *info;
  66.   svpmi_modeentry *sm;
  67.  
  68.   if (mode < 10)
  69.     return vga_chipsetfunctions[CHIPSET_MODEAVAILABLE] (mode);
  70.   if (mode == 32)
  71.     return 0;
  72.  
  73.   sm = svpmi_lookupmode (modeinfo->width, modeinfo->height,
  74.              modeinfo->colors);
  75.   return (sm != NULL)
  76. }
  77.  
  78.  
  79. /* Set a mode */
  80.  
  81. static int
  82. svpmi_setmode (int mode, int prv_mode)
  83. {
  84.   svpmi_modeentry *sm;
  85.  
  86.   if (mode == TEXT)
  87.     {
  88.       svpmi_setmode_text ();
  89.       return 0;
  90.     }
  91.  
  92.   if (!SVGAMODE (mode))
  93.     /* Let the standard VGA driver set standard VGA modes. */
  94.     return vga_chipsetfunctions[CHIPSET_SETMODE] (mode);
  95.  
  96.   sm = svpmi_lookupmode (infotable[mode].width, infotable[mode].height,
  97.              infotable[mode].colors);
  98.   if (sm == NULL)
  99.     return 1;            /* No match. */
  100.  
  101.   sm->setmode ();        /* Call the SVPMI mode setting code. */
  102.   svpmi_currentmode = sm;
  103.  
  104.   /* Hack similar to what the ATI mach32 driver does for some */
  105.   /* truecolor modes. I think S3 uses only a few fixed scanline */
  106.   /* widths (e.g. 1024, 1280) so may happen a lot. */
  107.   infotable[mode].xbytes = sm->bytesperscanline;
  108. }
  109.  
  110.  
  111. /* Indentify chipset; return non-zero if detected */
  112.  
  113. static int
  114. svpmi_test ()
  115. {
  116.   /* Detection with environment variable -- better change into */
  117.   /* config file option. */
  118.   if (getenv ("SVGALIB_SVPMI"))
  119.     return 1;
  120.   return 0;
  121. }
  122.  
  123.  
  124. /* Bank switching function - set 64K bank number */
  125.  
  126. static void
  127. svpmi_setpage (int page)
  128. {
  129.   svpmi_currentmode->setwindow (page *
  130.                 (64 / svpmi_currentmode->windowgranularity));
  131. }
  132.  
  133.  
  134. /* Set display start address (not for 16 color modes) */
  135.  
  136. static int
  137. svpmi_setdisplaystart (int address)
  138. {
  139. }
  140.  
  141.  
  142. /* Set logical scanline length (usually multiple of 8) */
  143. /* Multiples of 8 to 2040 */
  144.  
  145. static int
  146. svpmi_setlogicalwidth (int width)
  147. {
  148.   outw (0x3d4, 0x13 + (width >> 3) * 256);    /* lw3-lw11 */
  149.   return 0;
  150. }
  151.  
  152. static int
  153. nothing ()
  154. {
  155. }
  156.  
  157.  
  158. /* Function table (exported) */
  159.  
  160. int (*svpmi_chipsetfunctions[]) () =
  161. {
  162.   (int (*)()) nothing,        /* saveregs */
  163.     (int (*)()) nothing,    /* setregs */
  164.     (int (*)()) nothing,    /* unlock */
  165.     (int (*)()) nothing,    /* lock */
  166.     svpmi_test,
  167.     svpmi_init,
  168.     (int (*)()) svpmi_setpage,
  169.     (int (*)()) nothing,
  170.     (int (*)()) nothing,
  171.     svpmi_setmode,
  172.     svpmi_modeavailable,
  173.     nothing,            /* setdisplaystart */
  174.     svmi_setlogicalwidth,
  175.     svpmi_getmodeinfo
  176. };
  177.  
  178.  
  179. /* Initialize chipset (called after detection) */
  180.  
  181. static int
  182. svpmi_init (int force, int par1, int par2)
  183. {
  184.   /* Not required. */
  185. }
  186.